package net.sk.demo.client;

import net.sk.demo.api.TimeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Scanner;

/**
 * @author sk.z
 */
@Component
public class Console {

    @DubboReference(check = false)
    private TimeService timeService;

    @PostConstruct
    public void start() {
        new Thread(() -> {
            Scanner scanner = new Scanner(System.in);
            System.out.print("cmd:>");
            while (scanner.hasNextLine()) {
                try {
                    String cmd = scanner.nextLine();
                    if (cmd.equals("now")) {
                        System.out.println(timeService.now());
                    } else {
                        System.out.println("get:" + cmd);
                    }
                } catch (Exception ignored) {
                }
                System.out.print("cmd:>");
            }
        }).start();
    }
}
